package com.baseDemo.web.interceptors;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.baseDemo.web.entity.UserEntity;
import com.baseDemo.web.server.SystemServer;

public class JspFilter implements Filter{

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
	}

	@Override
	public void doFilter(ServletRequest servletRequest, ServletResponse response,
			FilterChain filterChain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest)servletRequest; 
		HttpSession session = request.getSession();
		UserEntity userEntity = (UserEntity)session.getAttribute(SystemServer.getInstance().get("USERSESSION").toString());
		if(userEntity==null){
			request.getRequestDispatcher("login").forward(request, response);  
		}else{
			filterChain.doFilter(servletRequest, response);
		}
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

}
